package ru.susu.algebra.ranks;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

/**
 * @author akargapolov
 * @since 03.12.2011
 */
public class FromSquareFileRanksProvider
{
	private static final int NUM_LINES = 8;
	
	public static Map<Integer, String> ranks = new HashMap<Integer, String>();
	public static Map<Integer, String> squares = new HashMap<Integer, String>();

	static
	{
		try
		{
			fillMaps();
		}
		catch(Exception e)
		{
			throw new RuntimeException(e);
		}
	}
	
	private static void fillMaps() throws Exception
	{
		BufferedReader reader = new BufferedReader(new FileReader("Ranks/FullDPRanksCounterNewSquare.txt"));

		int n = 1;

		int counter = 0;
		String rank = null;
		while(true)
		{
			String line = reader.readLine();
			if (line == null)
				break;

			if (counter % NUM_LINES == 0)
			{
				rank = line.substring(StringUtils.lastIndexOf(line, " ") + 1);
				ranks.put(n, rank);
			}
			else if (counter % NUM_LINES == 1)
			{
				String square = line.substring(StringUtils.lastIndexOf(line, " ") + 1);
				squares.put(n, square);
				n++;
			}

			counter++;
		}
	}
}
